package generator.config;

import cn.hutool.core.util.StrUtil;
import lombok.Data;
import lombok.experimental.Accessors;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Properties;

/**
 * <p>
 *
 * </p>
 *
 * @author angel.bin@aliyun.com
 * @since 2020-10-05 13:49
 */
@Data
@Accessors(chain = true)
public class TableMapConfig {
    private static TableMapConfig tableMapConfig;

    static {
        try (InputStream in = TableMapConfig.class.getClassLoader().getResourceAsStream("table-map.properties")) {
            Properties properties = new Properties();
            properties.load(in);
            tableMapConfig = new TableMapConfig()
                    .setTablePrefixes(StrUtil.split(properties.getProperty("tablePrefixes"), ','))
                    .setTableIgnores(StrUtil.split(properties.getProperty("tableIgnores"), ','))
                    .setColumnPrefixes(StrUtil.split(properties.getProperty("columnPrefixes"), ','))
                    .setTableLogic(properties.getProperty("tableLogic"))
                    .setJsonIgnores(StrUtil.split(properties.getProperty("jsonIgnores"), ','));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private List<String> tablePrefixes;
    private List<String> tableIgnores;
    private List<String> columnPrefixes;
    private String tableLogic = "is_deleted";
    private List<String> jsonIgnores = List.of("is_deleted");

    public static TableMapConfig getInstance() {
        return TableMapConfig.tableMapConfig;
    }
}
